package day19.zhiyou100;


public class Demo002 {

    public static void main(String[] args) {

        //TicketSystem tS = new TicketSystem();
        // 创建多线程 洛阳

        TicketSystem Ly = new TicketSystem();
        // 郑州
        TicketSystem Zz = new TicketSystem();
        TicketSystem Bj = new TicketSystem();

        Ly.start();
        Zz.start();
        Bj.start();

    }
}

class Piao {
    static Integer num = 200;

}

class TicketSystem extends Thread {
    private Piao piao;
    private final Object obj = new Object();

    @Override
    public void run() {
        for (int i = 1; i < 1000; i++) {
            synchronized (obj) {
                if (Piao.num > 0) {
                    Piao.num--;
                    System.out.println("还剩" + Piao.num + "张票");
                } else {
                    break;
                }
            }
        }
    }
}